/************************************* * File: Rectangle.cpp * Author: Katherine Gibson * Date: 2/18/2016 * Section: N/A * E-mail: k38@umbc.edu * Description: * This file contains the full * definition for a rectangle class *************************************/ #include "Rectangle.h" #include using namespace std; /* because this is the DEFINTION, we don't need things like the member variables or the "class" keyword */ /**********************************/ /* methods of the Rectangle class */ /**********************************/ // Constructor // Rectangle::Rectangle(int width, int height, string color) { // initialize each member variable SetWidth(width); SetHeight(height); SetColor(color); } void Rectangle::PrintInfo() { cout << "Color is '" << m_color << "'" << endl; cout << "Width is " << m_width << endl; cout << "Height is " << m_height << endl; } // CalcArea // returns area of Rectangle int Rectangle::CalcArea(void){ int area = m_width * m_height; return area; } // CalcPerim // returns perimteter of Rectangle int Rectangle::CalcPerim(void){ return 2 * (m_height + m_width); } // Rotate // switches m_width and m_height to "rotate" Rectangle void Rectangle::Rotate() { int temp = m_height; m_height = m_width; m_width = temp; } // IsSquare // returns if m_width and m_height are equal bool Rectangle::IsSquare() { if (m_height == m_width) { return true; } else { return false; } /* We could also accomplish the above in one line: return (m_height == m_width); */ } int Rectangle::GetWidth() { return m_width; } int Rectangle::GetHeight() { return m_height; } string Rectangle::GetColor() { return m_color; } void Rectangle::SetWidth(int width) { if (width >= 1) { m_width = width; } else { m_width = DEFAULT_SIZE; } } void Rectangle::SetHeight(int height) { if (height >= 1) { m_height = height; } else { m_height = 1; } } void Rectangle::SetColor(string color) { m_color = color; }